import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author mjy
 * @date 2021/10/26
 * @description
 */
public class GetGpsThreadFun extends Thread {

    private Socket vntThreadClient;


    public GetGpsThreadFun(Socket vntThreadSocket){
        vntThreadClient=vntThreadSocket;
    }

    @Override
    public void run() {
        try {
            //显示时间
            Date day=new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(df.format(day));
            byte[] data = new byte[1024];
            while (true){
                int len = vntThreadClient.getInputStream().read(data);
                 if (len>0){
                     //打印客户端IP：端口:接收的数据（字符串的转化方法)
                     System.out.println(vntThreadClient.getInetAddress()+":"+vntThreadClient.getPort()+":"+new String(data,0,len));
                     //给客户端返回TCP
                     vntThreadClient.getOutputStream().write("TCP".getBytes());
                     if("shutdown".equals(vntThreadClient)){
                         //停止本次循环
                         break;
                     }
                 }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
